package cn.wsalix.observable.service.impl;

import java.util.List;
import java.util.Observable;
import java.util.Observer;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import cn.wsalix.admin.entity.SysUser;
import cn.wsalix.admin.form.UserForm;
import cn.wsalix.observable.service.UserInfoUpService;
import cn.wsalix.user.service.AddressService;
import cn.wsalix.user.service.UserInfoService;
import cn.wsalix.utils.UserUtils;

public class UserInfoUpServiceImpl extends Observable implements
		UserInfoUpService {
	protected Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private UserInfoService userInfoService;
	@Autowired
	private AddressService addressService;
	private SysUser user;
	private List<? extends Observer> serviceList;

	@PostConstruct
	public void init() {
		if (serviceList != null) {
			for (Observer obj : serviceList) {
				addObserver(obj);
			}
		}
		logger.info("==========init");

	}

	@PreDestroy
	public void destroy() {
		logger.info("==========destroy");
	}

	@Transactional
	@Override
	public SysUser change(UserForm entity) {
		setChanged();
		notifyObservers(entity);
		return user;
	}

	public SysUser getUser() {
		return user;
	}

	public void setUser(SysUser user) {
		this.user = user;
	}

	@Autowired
	protected UserUtils userUtils;

	public List<? extends Observer> getServiceList() {
		return serviceList;
	}

	public void setServiceList(List<? extends Observer> serviceList) {
		this.serviceList = serviceList;
	}

}
